package com.haiyou.common.util.time;


import java.util.Date;

public class DateBetween {

	private Date begin;
	private Date end;

	public static DateBetween create(Date begin, Date end) {
		return new DateBetween(begin, end);
	}

	public static DateBetween create(Date begin, Date end, boolean isAbs) {
		return new DateBetween(begin, end, isAbs);
	}

	public DateBetween(Date begin, Date end) {
		this(begin, end, true);
	}

	public DateBetween(Date begin, Date end, boolean isAbs) {
		if (isAbs && begin.after(end)) {
			this.begin = end;
			this.end = begin;
		} else {
			this.begin = begin;
			this.end = end;
		}
	}

	public long between(DateUnit unit) {
		long diff = end.getTime() - begin.getTime();
		return diff / unit.getMillis();
	}


}
